# -*-coding:utf-8-*-

from tests.apis.http import *
from tests.apis.base import BaseAPI


class Products(BaseAPI):
    def __init__(self, *args, **kwargs):
        super(Products, self).__init__(*args, **kwargs)

    def create_product(self, *args, **kwargs):
        response = http_post('platform/api/products', kwargs, self.query)
        return self.assert_response_success_data(response)

    def delete_product(self, *args, **kwargs):
        product_id = kwargs.pop('product_id')
        response = http_delete('platform/api/products/%s' % product_id, query=self.query)
        return self.assert_response_success_data(response)

    def update_product(self, *args, **kwargs):
        product_id = kwargs.pop('product_id')
        response = http_put('platform/api/products/%s' % product_id, kwargs, query=self.query)
        return self.assert_response_success_data(response)

    def update_product_specifics(self, *args, **kwargs):
        product_id = kwargs.pop('product_id')
        response = http_put('platform/api/products/%s/specifics' % product_id, kwargs, query=self.query)
        return self.assert_response_success_data(response)

    def get_product(self, *args, **kwargs):
        product_id = kwargs.pop('product_id')
        response = http_get('platform/api/products/%s' % product_id, self.query)
        return self.assert_response_success_data(response)

    def get_product_specifics_field(self, *args, **kwargs):
        product_id = kwargs.pop('product_id')
        field = kwargs.pop('field')
        response = http_get('platform/api/products/%s/specifics/%s' % (product_id, field), self.query)
        return self.assert_response_success_data(response)

    def get_product_list(self, *args, **kwargs):
        response = http_get('platform/api/products', self.query)
        return self.assert_response_success_data(response)

    def get_product_count(self, *args, **kwargs):
        response = http_get('platform/api/products/count', self.query)
        return self.assert_response_success_data(response)
